//
//  CashierBuyCarView.m
//  DiningCar-Business
//
//  Created by 吕晶 on 2020/4/13.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "CashierBuyCarView.h"

@interface CashierBuyCarView ()

@property (nonatomic, strong) UIImageView *logoImgView;
@property (nonatomic, strong) UILabel *countLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UIButton *commitBtn;

@end

@implementation CashierBuyCarView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = HexColor(0xffffff);
        self.logoImgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 0, 50, 42)];
        self.logoImgView.image = [UIImage imageNamed:@"cashier_buy_car"];
        [self addSubview:self.logoImgView];
        
        self.countLab = [[UILabel alloc] initWithFrame:CGRectMake(self.logoImgView.nim_right - 19, 0, 24, 18)];
        self.countLab.backgroundColor = HexColor(0xFF5858);
        self.countLab.layer.masksToBounds = YES;
        self.countLab.layer.cornerRadius = 9;
        self.countLab.textColor = HexColor(0xffffff);
        self.countLab.font = BoldFontOfSize(12);
        self.countLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.countLab];
        
        self.priceLab = [[UILabel alloc] initWithFrame:CGRectMake(self.logoImgView.nim_right + 10, 16, ScreenW - 100 - (self.logoImgView.nim_right + 10), 18)];
        self.priceLab.textColor = HexColor(0x2B2C44);
        self.priceLab.font = BoldFontOfSize(16);
        self.priceLab.text = @"合计：0元";
        [self addSubview:self.priceLab];
        
        self.commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenW - 90, 8, 68, 34)];
        [self.commitBtn setBackgroundColor:HexColor(0xFF5858)];
        self.commitBtn.layer.cornerRadius = 17;
        [self.commitBtn setTitle:@"结算" forState:0];
        [self.commitBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.commitBtn.titleLabel.font = BoldFontOfSize(14);
        [self addSubview:self.commitBtn];
    }
    return self;
}

-(void)setGoodArray:(NSArray<CashierClassGoodModel *> *)goodArray {
    _goodArray = goodArray;
    if (goodArray.count) {
        self.countLab.hidden = NO;
        __block CGFloat allPrice = 0;
        [goodArray enumerateObjectsUsingBlock:^(CashierClassGoodModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            allPrice += obj.count * [obj.price floatValue];
        }];
        self.priceLab.text = [NSString stringWithFormat:@"合计：%.2f元",allPrice];
    }else {
        self.countLab.hidden = YES;
        self.priceLab.text = @"合计：0元";
    }
}

@end
